<?php
/**
 * Created by PhpStorm.
 * User: MI
 * Date: 2018/10/12
 * Time: 14:49
 */

namespace App\Models;


use Illuminate\Database\Eloquent\Model;

class SMSConfirmationCode extends Model
{
    protected $table = 'sms_confirmation_code';
    /**
     * @param int $length
     * @return int
     */
    public function generateSMSConfirmationCode($length = 6)
    {
        return mt_rand(pow(10, ($length - 1)), pow(10, $length) - 1);
    }

    /**
     *
     * @param unknown $userCode
     * @param unknown $dbCode
     * @param unknown $expired
     * @return boolean
     */
    public function checkSMSConfirmationCode($userCode, $dbCode, $expired)
    {
        \Log::info([strtotime($expired), time(), strtotime($expired) > time()]);
        if ($userCode === $dbCode && strtotime($expired) > time()) {
            return true;
        } else {
            return false;
        }
    }
}